package daoImpl;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import dao.GoodsDao;
import entlty.Erji;
import entlty.Goods;
import utils.BaseDao;

public class GoodsDaoImpl extends BaseDao implements GoodsDao{

	@Override
	public List<Goods> getAll(int gid) {
		List<Goods> list=new ArrayList<Goods>();
		String sql="select  * from goods g join erji e on g.e_id=x_sid where g.gid=?";
		ResultSet rs=super.exeQuery(sql,gid);
		try {
			while(rs.next()){
				Goods g=new Goods(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getInt(4));
				Erji e=new Erji(rs.getInt("e_id"),rs.getString("e_name"),rs.getInt("x_sid"));
				g.setErji(e);
				list.add(g);
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		return list;
	}

	@Override
	public List<Goods> getAll() {
		List<Goods> list=new ArrayList<Goods>();
		String sql="select  * from goods";
		ResultSet rs=super.exeQuery(sql);
		try {
			while(rs.next()){
				Goods g=new Goods(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getInt(4));
				list.add(g);
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		return list;
	}

}
